/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package evaluateur;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
import model.DBWriter;

/**
 *
 * @author Cyril
 */
public class QRelUtils {
    
    //private final String workspace = "C:/Users/Cyril/Desktop/ReppConn/Qrels/";
    
    public static ArrayList<Integer> readQRelFile(String filePath, DBWriter db) {
        ArrayList<Integer> res = new ArrayList<Integer>();
        
        try {
            Scanner s = new Scanner(new FileReader(filePath));
            String file, xpath;
                  
            while (s.hasNextLine()) {
                try {
                    file = s.next();
                    xpath = s.next();
                    if (s.nextInt()==1) {
                        res.add(db.getNodeIdFromNodeInfo(file, xpath));
                    }      
                } catch(Exception e) {
                    System.out.println("Attention : Ligne malformée lue dans "+filePath);
                }      
            }
        } catch (FileNotFoundException ex) {            
            Logger.getLogger(QRelUtils.class.getName()).log(Level.SEVERE, null, ex);
            System.out.println("Fichier non trouvé : "+filePath);
        }
        
        return res;
    }
    
}
